CONTENTS | INDEX | PREV | NEXT
 strchr

   NAME
    strchr  - search for a character in a string

   SYNOPSIS
    char *ptr = strchr(s, c)
    const char *s;
    int c;

   FUNCTION
    Searches for the character c within the string pointed to by
    s.  The terminating nul at the end of s is included in the search.

    A pointer to the first occurance of c in s is returned or NULL
    if c could not be found.

    c is converted to a char by strchr() before beginning the search.

   NOTE
    while strchr(s, 0); may be used to find the end of the string this
    is slow compared to using the construction:

        char *ptr = s + strlen(s);    /*  ptr = end of string s       */

   EXAMPLE
    #include <stdio.h>
    #include <string.h>
    #include <assert.h>

    main()
    {
        char *s = "this is a test";
        char *ptr;

        ptr = strchr(s, 'i');
        assert(ptr == s + 2);

        puts(ptr);              /*  "is is a test"  */
        return(0);
    }

   INPUTS
    char *s;    pointer to the string to search
    int c;      character to search for

   RESULTS
    char *ptr;  pointer to the first occurance of character c in
            s or NULL if c could not be found in s.

   SEE ALSO
    strrchr